<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>专家咨询</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
</head>
<body>
    <table id="demo" lay-filter="test" ></table>
    <script>
        var table2 = null;
        var table = null;
        var name=null;
        layui.use('table', function(){
            table = layui.table;
            table2=table.render({
                elem: '#demo'
                ,height: 570
                ,toolbar: '#toolbarDemo'
                ,url: '../../mase/MentalityExpertFindAll' //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'saName', title: '方案名'}
                    ,{field: 'applyForTime', title: '申请时间',  sort: true}
                    ,{field: 'applyForExp', title: '申请理由', sort: true}
                    ,{field: 'auditState', title: '审核状态',templet:function(obj){
                        if(obj.auditState=="10"){
                            return "申请中";
                        }else if(obj.auditState=="20"){
                            return "领导已同意";
                        }else if(obj.auditState=="21"){
                            return "领导未同意";
                        }else if(obj.auditState=="30"){
                            return "待回复";
                        }else if(obj.auditState=="40"){
                            return "已回复";
                        }
                        }}
                    ,{field: 'expertName', title: '专家姓名',templet:function(obj){
                            if(obj.expertName==''||obj.expertName=='null'||obj.expertName==null){
                                return "无";
                            }else{
                                return obj.expertName;
                            }
                        }}
                    ,{field: 'results',title: '专家咨询结果',templet:function(obj){
                            if(obj.results==''||obj.results=='null'||obj.results==null){
                                return "无";
                            }else{
                                return "<a href='../../"+obj.results+"' class='layui-btn layui-btn-xs'>下载</a>";
                            }
                        }}
                    ,{title: '操作',fixed: 'right', width:180, align:'center', toolbar: '#barDemo'}
                ]]
            });
            /* 头部工具栏监听 */
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data; //获取选中的数据
                switch(obj.event){
                    case 'search':
                        name=$("#schemeName").val();
                        //执行重载
                        table2.reload({
                            url:'../../mase/MentalityExpertFindAll',
                            page: {
                                curr: 1 //重新从第 1 页开始ffffffff
                            }
                            ,where: {
                                saName: $("#schemeName").val()
                            }
                        });
                        $("#schemeName").val(name);
                        break;
                };
            });

            //监听工具条
            table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                console.info(data);
                if(layEvent === 'look'){ //编辑
                    layer.open({
                        type: 2,
                        title:'查看页面',
                        shadeClose:true,
                        shade:0.8,
                        area:['45%','60%'],
                        content: ['../xy/MentalityAtsSchemeExpertLook.html?id='+data.schemeId], //数组第二项即吸附元素选择器或者DOM
                        end:function(){
                            //刷新表格
                            table2.reload();
                        }
                    });
                }
            });
        });
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-input-inline" style="float:left;margin-left:15px;">
            <input type="text" placeholder="请输入方案名" id="schemeName" class="layui-input" style="width:200px;float:left;height:32px;">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="search" id="search" style="margin-left: 10px;">搜索</button>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    </script>
    <script type="text/html" id="resultDemo">
        <a href="../../{{d.results}}" class="layui-btn layui-btn-xs">下载</a>
    </script>
</body>
</html>